# Maintainer: David Runge <dvzrv@archlinux.org>

_name=i18n
pkgname=ruby-i18n
pkgver=1.12.0
pkgrel=1
pkgdesc="New wave internationalisation support for Ruby"
arch=(any)
url="https://github.com/ruby-i18n/i18n"
license=(MIT)
depends=(ruby ruby-concurrent)
makedepends=(ruby-rdoc)
checkdepends=(ruby-bundler ruby-activesupport ruby-json ruby-minitest ruby-mocha ruby-rake ruby-test_declarative)
options=(!emptydirs)
source=($pkgname-$pkgver.tar.gz::https://github.com/$pkgname/$_name/archive/v$pkgver.tar.gz)
sha512sums=('616db5b15febc7a8716ceafef6c51a24e2d050f8e27e389ef96d94cdc95f9704942079d1e6b502666a015a99deee169342482c9a808164700401c47f96da8f0d')
b2sums=('6818e5bdea156e9b6f7b33e319e5b5a5c3c9e7a799b56ded87ab2e27efa4effe730e23a8736b7374b8072c7ba4237a92619aeaad3a16c0bfe10fe73bf9c588d6')

prepare() {
  cd $_name-$pkgver
  # we do not do version pinning
  sed -e 's,~>,>=,g' -i *.gemspec Gemfile Rakefile
  # lockfiles should be removed
  rm -fv Gemfile.lock
  # do not rely on Gemfiles (unless the project *really* needs it)
  rm -fv Gemfile
}


build() {
  cd $_name-$pkgver
  gem build $_name.gemspec
}

check(){
  cd $_name-$pkgver
  rake test
}

package() {
  local _gemdir="$(gem env gemdir)"

  cd "$_name-$pkgver"
  gem install \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "$pkgdir/$_gemdir" \
    --bindir "$pkgdir/usr/bin" \
    "$_name-$pkgver.gem"

  # remove unrepreducible files
  rm -frv \
    "$pkgdir/$_gemdir/cache/" \
    "$pkgdir/$_gemdir/gems/$_name-$pkgver/vendor/" \
    "$pkgdir/$_gemdir/doc/$_name-$pkgver/ri/ext/"

  find "$pkgdir/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete

  find "$pkgdir/$_gemdir/extensions/" \
    -type f \
    \( \
      -iname "mkmf.log" -o \
      -iname "gem_make.out" \
    \) \
    -delete

  install -vDm 644 MIT-LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
